package com.example.presenters;

import java.util.ArrayList;

import com.example.db.db;
import com.example.model.Date;
import com.example.model.Item;
import com.example.model.ItemList;

/**
 * This is the item presenter. It will show items in the future.
 * 
 * @author 3Factorial
 */
public class ItemListPresenter {

	private ItemList itemList;

	/**
	 * Creates an instance of the ItemListPresenter, which maintains a copy of
	 * the current list of user-created items for displaying purposes.
	 */
	public ItemListPresenter() {
		itemList = ItemList.getInstance();
		db dbaccess = new db();
		dbaccess.getItems(itemList);//TENTATIVE
	}

	/**
	 * Retrieves a list of all items that match all the given filter criteria.
	 * 
	 * @param filters
	 *            List of filters to match with items.
	 * @return All items that match the filters.
	 */
	public ArrayList<Item> getMatchedItems(ArrayList<String> filters) {
		return itemList.getMatchItems(filters);
	}

	/**
	 * Sorts the item list by date.
	 * 
	 * @param start
	 *            Start date.
	 * @param end
	 *            End date.
	 * @return Sorted list of items by date.
	 */
	public ArrayList<Item> sortByDate(Date start, Date end) {
		ArrayList<Item> toReturn = new ArrayList<Item>();
		for (Item i : itemList.getAllItems())
			if (i.getDate().isBefore(end) && !i.getDate().isBefore(start))
				toReturn.add(i);
		return toReturn;
	}

	/**
	 * Gets an array list of all items.
	 * 
	 * @return All items.
	 */
	public ArrayList<Item> getAllItems() {
		return itemList.getAllItems();
	}

	/**
	 * Retrieves a list of all lost items.
	 * 
	 * @return All lost items.
	 */
	public ArrayList<Item> getAllLostItems() {
		return itemList.getAllLostItems();
	}

	/**
	 * Retrieves a list of all found items.
	 * 
	 * @return All found items.
	 */
	public ArrayList<Item> getAllFoundItems() {
		return itemList.getAllFoundItems();
	}
	
	/**
	 * Retrieves a list of all items with a given name.
	 * @param name
	 * @return All items with the matching name
	 */
	public ArrayList<Item> getNamedItems(String name) {
		return itemList.getAllMatchedNames(name);
	}

} // End ItemPresenter
